package com.student.manager.servlet;

import com.student.manager.bean.Student;
import com.student.manager.dao.impl.StudentDaoImpl;
import com.student.manager.service.StudentService;
import com.student.manager.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/EditServlet")
public class EditServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {

            int sid = Integer.parseInt(request.getParameter("sid"));

            StudentService service = new StudentServiceImpl();
            Student student = service.findStudentById(sid);

            request.setAttribute("stu", student);
            request.getRequestDispatcher("edit.jsp").forward(request, response);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
